home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
GRAPH_FO
/
(GRAPH
/
CGRAPHTE
/
CGRAPHAP.C
next >
Wrap
Text File
|
1991-02-15
|
9KB
|
267 lines
/******************************************************************************
CGraphApp.c
The GraphApp Class
SUPERCLASS = CApplication.c
Copyright ⌐ 1991 Maarten Meijer. All rights reserved.
CIS 100016,1764; FidoNet 2:512/114
*******************************************************************************/
/* includes */
#include <Global.h>
#include <Commands.h>
#include <CFWDesktop.h>
#include <CBartender.h>
#include "GraphCommands.h"
#include "CGraphApp.h"
#include "CGraphDoc.h"
/* externs */
extern CBartender *gBartender;
extern CDesktop *gDesktop; /* The visible Desktop */
extern OSType gSignature; /* Creator for Application's files */
CursHandle gCrossCursor;
CursHandle gGrabCursor;
/* methods */
/******************************************************************************
IGraphApp
Initialize a GraphApp object
******************************************************************************/
void CGraphApp::IGraphApp()
{
/* Initialize superclass */
/* $$$ Parameters are the number of times to call MoreMasters, */
/* the number of bytes of heap space to reserve for monitoring */
/* low memory situations, and credit limit for memory requests. */
/* Four (4) is a reasonable number of MoreMasters() calls, */
/* but you should determine a good number for your application */
/* by observing the heap using an object code debugger such as */
/* TMON or Macsbug. Set this parameter to zero, give your */
/* program a rigorous work-out, then look at the heap and count */
/* how many master pointer blocks have been allocated. Master */
/* pointer blocks are nonrelocatable and have a size of 0x100 */
/* (hex). You should call MoreMasters() at least this many */
/* times -- add a few extra just to be safe. The purpose of all */
/* this preflighting is to prevent heap fragmentation. You */
/* don't want the Memory Manager to call MoreMasters() and */
/* create a nonrelocatable block in the middle of your heap. By */
/* calling MoreMasters() at the very beginning of the program, */
/* you ensure that these blocks are allocated in a group at the */
/* bottom of the heap. */
/* The memory reserve is a safeguard for handling low memory */
/* conditions and is used by the GrowMemory() method in */
/* CApplication (check there for more comments). In general, */
/* your program should never request a memory block greater */
/* than this reserve size without explicitly checking in */
/* advance whether there is enough free memory to satisfy the */
/* the request. */
/* The credit limit specifies a cut-off level for memory */
/* requests which can tap the memory reserve. Requests larger */
/* than this size will not use the memory reserve when the */
/* system pleads for more memory. */
CApplication::IApplication(10, 20000L, 2000L);
/* &&& Initialize global variables defined by your */
/* application and the instance variables of */
/* your Application subclass. */
gCrossCursor = GetCursor(crossCursor);
gGrabCursor = GetCursor(9);
}
/******************************************************************************
SetUpFileParameters {OVERRIDE}
Set parameters used by the Standard File Package
******************************************************************************/
void CGraphApp::SetUpFileParameters()
{
inherited::SetUpFileParameters(); /* Use defaults from superclass */
/* &&& Specify file parameters for the Application */
gSignature = 'Graf'; /* XXX Specify a four-character */
/* signature for your application */
sfNumTypes = 1; /* XXX Specify the number and types */
sfFileTypes[0] = 'Graf'; /* of files recognized. This app */
/* opens pictures and paintings. */
}
/******************************************************************************
SetUpMenus {OVERRIDE}
Set up menus which must be created at run time, such as a
Font menu. You can eliminate this method if your application
does not have any such menus.
******************************************************************************/
void CGraphApp::SetUpMenus()
{
inherited::SetUpMenus(); /* Superclass takes care of adding */
/* menus specified in a MBAR id=1 */
/* resource */
/* &&& Code for creating run-time menus */
/* gBartender->InsertHierMenu(MENUsize, cmdSize, MENUlayout, 1); */
AddResMenu(GetMHandle(MENUfont), 'FONT');
gBartender->SetDimOption(MENUfont, dimNONE);
gBartender->SetDimOption(MENUsize, dimNONE);
/**
** For Font and Size menus, one of the items
** is always checked. Setting the unchecking option
** to TRUE lets the bartender know that it should
** uncheck all the menu items because an UpdateMenus()
** method will check the right items.
** For the Style menu, uncheck all the items and
** let the edit pane's UpdateMenus() method check the
** appropriate ones.
**
**/
gBartender->SetUnchecking(MENUfont, TRUE);
gBartender->SetUnchecking(MENUsize, TRUE);
}
/******************************************************************************
DoCommand {OVERRIDE}
Execute a command
$$$ Command numbers are longs, where command numbers 1 - 1023
are reserved, 0 is a special flag indicating a nonexistant
command (sort of like a NOP), and negative numbers indicate
a command which was added at run time (the high word is
the negative of the MENU id, and the low word is the item
number within that menu).
It's important to pass along commands not handled by this
class to the inherited DoCommand method. These commands
will be handled by the THINK Class Library in a default manner.
******************************************************************************/
void CGraphApp::DoCommand(
long theCommand)
{
switch (theCommand) {
/* &&& Cases for commands handled by your application */
default: /* Invoke inherited method to */
/* handle other commands */
inherited::DoCommand(theCommand);
break;
}
}
/******************************************************************************
UpdateMenus {OVERRIDE}
Perform menu management tasks
******************************************************************************/
void CGraphApp::UpdateMenus()
{
inherited::UpdateMenus(); /* Enable standard commands */
/* &&& Enable the commands handled by your Application class */
}
/******************************************************************************
Exit {OVERRIDE}
Program is about to terminate. Last chance to clean up.
$$$ Here's the place to delete temporary files or to automatically
save settings. However, most applications don't need to do
anything here and can elimate this method.
******************************************************************************/
void CGraphApp::Exit()
{
/* &&& Exit code for your application */
}
/******************************************************************************
CreateDocument {OVERRIDE}
Make a document. This message is sent when the user chooses the
"New" command.
******************************************************************************/
void CGraphApp::CreateDocument()
{
CGraphDoc *theDocument;
/* Create and initialize a Document */
/* $$$ Passing "this" to IGraphDoc */
/* means that the Application object */
/* is the supervisor of the Document */
theDocument = new(CGraphDoc);
theDocument->IGraphDoc(this);
theDocument->NewFile(); /* Tell Document to make a new file */
/* $$$ Document is responsible for */
/* do whatever's necessary to set up */
/* a new file (e.g., displaying a */
/* blank window) */
}
/******************************************************************************
OpenDocument {OVERRIDE}
Open an existing file and create a document object for displaying
information. This message is sent when the user chooses the
"Open..." command or when the application was launched by
double-clicking on a file or selecting file(s) and choosing
"Open" from the Finder.
The macSFReply parameter is a record which contains information
about the file to open (name, volume number, etc.).
******************************************************************************/
void CGraphApp::OpenDocument(
SFReply *macSFReply) /* Standard File reply record */
{
CGraphDoc *theDocument;
/* Create and initialize a Document */
/* $$$ Passing "this" to IGraphDoc */
/* means that the Application object */
/* is the supervisor of the Document */
theDocument = new(CGraphDoc);
theDocument->IGraphDoc(this);
/* Tell Document to open the file. */
/* $$$ The Document is responsible for */
/* creating whatever windows are */
/* necessary to display the file and */
/* actually reading the contents of */
/* the file from disk */
theDocument->OpenFile(macSFReply);
}